$(document).ready(function(){
	var token=localStorage.getItem("token");
	var id = tl_config.his_url;
	id = id.substring(id.indexOf("id=")+3, id.length);
	id = id.substring(0, id.indexOf("&"));
	$.ajax({
		url:server_url+"rest/assignPrecinct.do?ran="+Math.random(),
		type:"GET",
		data:{
			staffId:id,
			token:token
		},
		success:function(data){
			if(data.retCode='0000'){
				var settings={
					keyName:"areaId",
					parentKeyName:"parentId",
					childKeyName:"nodes"
				};
				var area=transformTozTreeFormat(settings,data.data);
				$.fn.tree.init({nodes:area});
			}else {
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});



	$(".z_sure").click(function(){
		var areaIdArr=new Array();
		$('input:checkbox:checked').each(function(i,v){
			areaIdArr.push($.parseJSON($(v).val()).areaId);
		});

		$.ajax({
			type:"post",
			url:server_url+"rest/savePrecinct.do?ran="+Math.random(),
			traditional:true,
			data:{
				postId:id,
				areaIdArr:areaIdArr,
				token:token
			},
			success:function(data){
				if(data.retCode='0000'){

					var url='postList.do?ran='+Math.random();
					tl_config.loadToWorkArea(url);
				}else {

					easyDialog.open({
						container:{
							header:'温馨提示',
							content:data.retMsg
						},
						autoClose : 2000
					});
				}
			}
		});
	});

	$(".z_goback").click(function(){
		var url='staffList.do?ran='+Math.random();
		tl_config.loadToWorkArea(url);
	});

});




